<template>
    <div>
        <iview-table
                ref="table"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :defaultFilters="queryModel.defaultFilters"
                v-on="{changeTotalSize:changeTotalSize,events:events,changeSelect:changeSelect}">
        </iview-table>
        <br>
        <iview-page
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
        </iview-page>
    </div>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    import iviewPage from '@/view/common/page/Page.vue';
    export default {
        components: {
            iviewTable,
            iviewPage
        },
        props: {

        },
        data () {
            return {
                selectRows: [],
                queryModel: {
                    // 网关代理路径(必须)+资源路径(可选)
                    baseURL: '/user/execute',
                    defaultFilters: [
                        {'field': 'complaint_id', 'value1': -1, 'operate': '=='}
                    ]
                },
                dataModel: {
                    menuId: 660,
                    columns: [
                        {
                            type: 'selection',
                            width: 60,
                            align: 'center'
                        },
                        {
                            title: '医嘱添加时间',
                            key: 'medicalTime',
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                return this.$moment(params.row.medicalTime).format('YYYY-MM-DD')
                            }
                        },
                        {
                            title: '项目/产品',
                            key: 'itemName',
                            width: 200,
                            className: 'demo-table-info-column'
                        },
                        {
                            title: '医嘱添加人',
                            key: 'doctorName',
                            className: 'demo-table-info-column'
                        },
                        {
                            title: '执行医嘱',
                            key: 'doctorRemark',
                            width: 200,
                            ellipsis: true,
                            className: 'demo-table-info-column'
                        },
                        {
                            title: '执行时间',
                            key: 'creationTime',
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                return this.$moment(params.row.creationTime).format('YYYY-MM-DD')
                            }
                        },
                        {
                            title: '执行人',
                            key: 'createdBy',
                            className: 'demo-table-info-column'
                        },
                        {
                            title: '执行备注',
                            key: 'executeContent',
                            width: 200,
                            ellipsis: true,
                            className: 'demo-table-info-column'
                        },
                        {
                            title: '总次数',
                            key: 'totalCount',
                            width: 100,
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                return params.row.totalCount + '次'
                            }
                        },
                        {
                            title: '剩余次数',
                            key: 'laveCount',
                            width: 100,
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                return params.row.laveCount + '次'
                            }
                        },
                        {
                            title: '收费/划扣',
                            key: 'cost',
                            className: 'demo-table-info-column'
                        },
                        {
                            title: '执行状态',
                            key: 'status',
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                let temp = params.row.status
                                if (temp === 0) {
                                    temp = '未执行'
                                } else if (temp === 1) {
                                    temp = '已执行'
                                }
                                return  temp
                            }
                        }
                    ],
                    order: 'creation_time desc'
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 100,
                    pageSizeOpts: [10, 50, 100, 500]
                }
            };
        },
        methods: {
            select (row) {
            },
            events (item) {
                let path = item.path
                if (path === 'print') {
                    this.printExecute()
                }
            },
            printExecute () {
                if (this.selectRows.length > 0) {
                    let ids = []
                    for (let row of this.selectRows) {
                        ids.push(row.id)
                    }
                    let url = this.$store.state.app.WEBROOT + '/user/print/adviceExecute?ids=' + ids + '&patientId=' + this.$store.state.app.patientId + '&userId=' + this.$store.state.app.loginUser.id
                    window.open(url)
                } else {
                    this.$bus.alert('warning', '请至少选择一条记录')
                }
            },
            refresh () {
                this.queryModel.defaultFilters[0] = {'field': 'complaint_id', 'value1': this.$store.state.app.complaintId, 'operate': '=='}
                this.$refs.table.refresh()
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
            },
            changePageSize (pageSize) {
                this.pageModel.pageSize = pageSize
            },
            init () {
                this.refresh()
            }
        },
        mounted () {
            this.init()
        },
        watch: {
            '$store.state.app.complaintId': function (val, oldVal) {
                this.queryModel.defaultFilters[0] = {'field': 'complaint_id', 'value1': val, 'operate': '=='}
            }
        }
    }
</script>

<style>

</style>
